/**
 * Created with IntelliJ IDEA.
 * Description:
 * https://gitee.com/li--jiaqiang/java-test.git
 * git pull
 * git pull origin master
 * git pull origin master --allow-unrelated-histories
 * User: 86187
 * Date: 2022-04-23
 * Time: 20:00
 */

//Scanner scan = new Scanner(System.in);

import java.util.Scanner;

public class TestDemo2 {

    /**
     * 模拟三次输入密码的场景
     * @param key
     */
    public static void password(String key) {
        Scanner scan = new Scanner(System.in);
        int count = 3;//三次机会
        while(count != 0) {
            System.out.println("请输入密码：");
            String str = scan.nextLine();
            if(str.equals(key)) {
                System.out.println("登录成功！");
                break;
            } else {
                count--;
                System.out.println("密码错误！请重新输入！");
                System.out.println("您还有"+count+"次机会！");
            }
        }
    }
    public static void main(String[] args) {
        String key = "dabogeyyds";//密码

        password(key);
    }
}
